import { GameListRep } from "@/api/home"; import { userInfoApi } from "@/api/login"; import { ChannelType, WithDrawParams, WithDrawType, getWithDrawApi } from "@/api/withdraw"; import { clearWallet } from "@/app/[locale]/(navbar)/withdraw/actions"; import TipsModal, { ModalProps } from "@/components/TipsModal"; import { ChannelEnum, ChannelEnumMap } from "@/enums"; import useGame from "@/hooks/useGame"; import { useRouter } from "@/i18n/routing"; import { useSystemStore } from "@/stores/useSystemStore"; import { useUserInfoStore } from "@/stores/useUserInfoStore"; import { useWalletStore } from "@/stores/useWalletStore"; import { isEmail } from "@/utils"; import { server } from "@/utils/client"; import { percentage } from "@/utils/methods"; import { Button, Form, Input, ProgressBar, Toast } from "antd-mobile"; import BigNumber from "bignumber.js"; import clsx from "clsx"; import { useTranslations } from "next-intl"; import React from "react"; import { Swiper, SwiperSlide } from "swiper/react"; import styles from "./index.module.scss"; const getWithdrawApi = async () => { return server .request({ url: "/v1/api/user/user_withdraw_config", method: "post", }) .then((res) => { if (res.code === 200) { return res.data; } return []; }); }; const Withdraw = () => { const t = useTranslations(); const router = useRouter(); const { getGameUrl } = useGame(); const [configData, setConfigData] = React.useState([] as WithDrawType[]); const [currentChannel, setCurrentChannel] = React.useState({} as WithDrawType); const [currentType, setCurrentType] = React.useState({} as ChannelType); const [amount, setAmount] = React.useState(""); const { wallet } = useWalletStore(); const isStrictMode = useSystemStore((state) => state.identity_verify.withdraw === 1); const userInfo = useUserInfoStore((state) => state.userInfo); // const canWithdrawRef = React.useRef(null); const formInstanceRef = React.useRef(null); const scoreRef = React.useRef(null); const gameModelRef = React.useRef(null); const game = React.useRef(null); const successModelRef = React.useRef(null); React.useEffect(() => { getData(); }, []); React.useEffect(() => { formInstanceRef.current?.resetFields(["account_no"]); }, [currentType]); React.useEffect(() => { formInstanceRef.current?.resetFields(); setAmount(""); }, [currentChannel]); const quicks = React.useMemo(() => { return [200, 500, 1000, 10000]; }, []); const faltaData = React.useMemo(() => { const { target_score_rollover, current_score_rollover, score, point, target_point_rollover, current_point_rollover, } = wallet; const total = target_score_rollover + target_point_rollover; const current = current_score_rollover + current_point_rollover; const waitScore = target_score_rollover - current_score_rollover; const waitPoint = target_point_rollover - current_point_rollover; let canWithdraw = true; if (waitScore !== 0 || waitPoint !== 0) { canWithdraw = false; } return { canWithdraw, percent: percentage(current, total), percentScore: (current_score_rollover / target_score_rollover) * 100, percentPoint: (current_point_rollover / target_point_rollover) * 100, waitScore, waitPoint, wait: waitScore + waitPoint, point, score: score || 0, }; }, [wallet]); const getData = async () => { const res = await getWithdrawApi(); if (res?.length > 0) { setConfigData(res); if (res[0]) { const cChannel = res[0]; setCurrentChannel(cChannel); const ctype = cChannel?.channels; if (ctype && ctype?.length > 0) { setCurrentType(ctype[0] || {}); } } } }; const channelChangeHandler = (item: WithDrawType) => { setCurrentChannel(item); if (item?.channels && item?.channels?.length > 0) { setCurrentType(item.channels[0]); } }; const valuesChange = (data: any) => { for (let key in data) { let curValue = data[key].trim(); switch (key) { case "amount": { let max = currentChannel.max_amount; if (faltaData.score < currentChannel.max_amount) { max = faltaData.score; } const toValue = inputNumber(curValue, { max }); setAmount(toValue); formInstanceRef.current?.setFieldValue(key, toValue); } break; case "account_no": { if (currentType.type === ChannelEnum.CPF) { const toValue = inputNumber(curValue, { length: 11 }); formInstanceRef.current?.setFieldValue(key, toValue); } if (currentType.type === ChannelEnum.CNPJ) { const toValue = inputNumber(curValue, { length: 14 }); formInstanceRef.current?.setFieldValue(key, toValue); } if (currentType.type === ChannelEnum.Phone) { const toValue = inputNumber(curValue, { length: 11 }); formInstanceRef.current?.setFieldValue(key, toValue); } if (currentType.type === ChannelEnum.Email) { const toValue = curValue.replace(/\s/gi, ""); formInstanceRef.current?.setFieldValue(key, toValue); } } break; case "passport": { const toValue = inputNumber(curValue, { length: 11 }); formInstanceRef.current?.setFieldValue(key, toValue); } break; } } }; const inputNumber = ( value: string, opts?: { max?: number; length?: number; } ) => { const toValue = value.replace(/[^0-9]/, ""); let toAmount = ""; if (toValue) { toAmount = new BigNumber(toValue).toFixed(0, BigNumber.ROUND_DOWN); } if (opts?.max !== undefined && new BigNumber(toAmount).isGreaterThan(opts.max)) { toAmount = opts.max.toString(); } if (opts?.length && toAmount.length > opts.length) { toAmount = toAmount.slice(0, opts.length); } return toAmount; }; const ChannelValidator = (rules: any, value: string) => { if (!value) return Promise.reject(new Error(t("WithdrawPage.channel"))); if (currentType.type === ChannelEnum.CPF) { return value.length !== 11 ? Promise.reject(new Error(t("WithdrawPage.cpfReg"))) : Promise.resolve(); } if (currentType.type === ChannelEnum.CNPJ) { return value.length !== 14 ? Promise.reject(new Error(t("WithdrawPage.cnpjReg"))) : Promise.resolve(); } if (currentType.type === ChannelEnum.Email) { return isEmail(value) ? Promise.resolve() : Promise.reject(new Error(t("WithdrawPage.EmailReg"))); } if (currentType.type === ChannelEnum.Phone) { return value.length < 10 ? Promise.reject(new Error(t("WithdrawPage.phoneReg"))) : Promise.resolve(); } return Promise.resolve(); }; const onFinish = async (value: any) => { const { data } = await userInfoApi(); if ( faltaData.score <= currentChannel.min_amount || new BigNumber(value.amount).isGreaterThan(faltaData.score) || faltaData.waitPoint !== 0 || faltaData.waitScore !== 0 ) { Toast.show("Quantidade insuficiente disponível para retirada"); return; } // 如果有未完成游戏 if (data.play_list && data.play_list.length > 0) { game.current = data.play_list[0]; gameModelRef.current?.onOpen(); return; } extractHandler(); }; const extractHandler = async () => { const values = formInstanceRef.current?.getFieldValues(); const { passport, name, last_name, amount, account_no } = values; if (!amount) { return; } const params: WithDrawParams = { passport, channel_id: currentType.id, amount: Number(amount), account_no, user_name: `${name} ${last_name}`, }; const withResult = await getWithDrawApi(params).catch((error) => { Toast.show(t(`code.${error.data.code}`)); }); if (withResult && withResult.code === 200) { Toast.show(t("code.200")); } await clearWallet(); }; // const goGame = () => { // const current = game.current; // getGameUrl(current!, { id: current?.id + "" }); // }; // const doCleanBonus = async () => { // try { // const res = await getUserTransferApi({ wallet_type: 2 }); // if (res.code === 200) { // Toast.show(t("code.200")); // setTimeout(() => { // successModelRef.current?.onClose(); // }, 1000); // } // } catch (error: any) { // Toast.show(t(`code.${error?.data?.code}`)); // } // }; return (
{configData?.map((item, index) => (
channelChangeHandler(item)} >
{/* */} {item.name}
R${item.min_amount}~{item.max_amount}
))}
ContaSaldo R$ {faltaData.canWithdraw ? faltaData.score : 0}
{ scoreRef.current?.onOpen(); }} >
{/*
Valor do Saque
*/} {/*
{quicks.map((item) => { return (
{ formInstanceRef.current?.setFieldValue("amount", item); setAmount(`${item}`); }} >
R$ {item}
); })}
*/}
A retirada minima após depositar R$ 10 é R$ 20
R$
} layout="horizontal" extra={
{ let toValue = 0; if (faltaData.canWithdraw) { toValue = faltaData.score; } formInstanceRef.current?.setFieldValue("amount", `${toValue}`); setAmount(`${toValue}`); }} > Todos
} name="amount" > setAmount(value)} placeholder={`${currentChannel.min_amount}~${currentChannel.max_amount}`} />
Método de Retirada {currentChannel.icon && (
)}
{currentChannel.channels?.map((item, index) => (
setCurrentType(item)} >
{ChannelEnum[item.type]}
))}
{(isStrictMode || currentType.type === ChannelEnum.CPF) && (
)} {isStrictMode && currentType.type !== ChannelEnum.CPF && ( )}
{/* 可以提取弹窗 */} {/* SACAR } ref={canWithdrawRef} getContainer={document.querySelector("#app")} className={styles.ModalBox} >
  • {t("WithdrawPage.scoreTips")} R$ {wallet.score}
  • {faltaData.percentScore}%
    FALTA APOSTAR R$ {faltaData.waitScore}
*/} {/*有彩金弹窗*/} SACAR } ref={scoreRef} getContainer={document.querySelector("#app")} className={styles.ModalBox} >
  • Conta Saldo R$ {faltaData.canWithdraw ? faltaData.score : 0}
  • {t("WithdrawPage.scoreTips")} R$ {wallet.score}
  • {t("WithdrawPage.pointTips")} R$ {wallet.point}
  • {faltaData.percent}%
  • FALTA APOSTAR R$ {faltaData.wait}
    {!faltaData.canWithdraw && ( )} {faltaData.canWithdraw && ( )}
{/* 提现拦截 */} {/*
Atualmente, existem jogos de bônus
inacabados que não podem iniciar saques.
} ref={gameModelRef} getContainer={document.querySelector("#app")} className={styles.gameModal} >
Bônus R$ {faltaData.point}
{faltaData.percentPoint}%
FALTA APOSTAR R$ {faltaData.waitPoint}
Saque bem-sucedida.
Seu bônus será liberado. Tem certeza?
} visible={true} ref={successModelRef} getContainer={document.querySelector("#app")} className={styles.gameModal} >
Bônus R$ {faltaData.point}
{faltaData.percentPoint}%
FALTA APOSTAR R$ {faltaData.waitPoint}
*/} ); }; export default Withdraw;